import request from '@/utils/request'
import * as cacheApi from '@/utils/cache'

function formatRequestUri(name, sysHead) {
  return sysHead + '/enum/' + name
}
export function GetItems(name, sysHead) {
  const key = 'EnumDic_' + name + '_' + sysHead
  const data = cacheApi.getCache(key)
  if (data != null) {
    return new Promise((resolve) => {
      resolve(data)
    })
  } else {
    return new Promise((resolve, reject) => {
      request({
        url: formatRequestUri('GetItems', sysHead),
        method: 'get',
        params: {
          name
        }
      }).then((res) => {
        cacheApi.setCache(key, res)
        resolve(res)
      }).catch(reject)
    })
  }
}
export function Gets(keys, sysHead) {
  return request({
    url: formatRequestUri('Gets', sysHead),
    method: 'post',
    data: keys
  })
}
